package org.sportspace.common.services

import org.sportspace.exception.DBException
import org.sportspace.base.domain.UserInfo

/**
 * 与domain类有关的公用服务
 */
class CommonService {

    public void saveOrUpdate(def domainObj, def errorMsg = null) throws Exception {
        def error = "";
        try {
            if (!domainObj.save(flush: true)) {

                domainObj.errors.each {
                    error += it
                }
            }
        } catch (Exception e) {
            log.error(e.message, e);
            throw new DBException(e.message);
        }

        if (error != "") {
            log.error(error);
            throw new DBException(error);
        }

    }

}
